{
 "metadata": {
  "name": "",
  "signature": "sha256:f17c223c02c0554d43202218faacb59b1b6afadc50e630c0a7533795ff2a3269"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import pandas as pd\n",
      "import numpy as np\n",
      "import cv2\n",
      "import os"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 67
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data = pd.read_csv('training.csv')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 68
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data.head().T"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-width:1500px;overflow:auto;\">\n",
        "<style scoped>\n",
        "    .dataframe tbody tr th:only-of-type {\n",
        "        vertical-align: middle;\n",
        "    }\n",
        "\n",
        "    .dataframe tbody tr th {\n",
        "        vertical-align: top;\n",
        "    }\n",
        "\n",
        "    .dataframe thead th {\n",
        "        text-align: right;\n",
        "    }\n",
        "</style>\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>0</th>\n",
        "      <th>1</th>\n",
        "      <th>2</th>\n",
        "      <th>3</th>\n",
        "      <th>4</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>left_eye_center_x</th>\n",
        "      <td>66.0336</td>\n",
        "      <td>64.3329</td>\n",
        "      <td>65.0571</td>\n",
        "      <td>65.2257</td>\n",
        "      <td>66.7253</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>left_eye_center_y</th>\n",
        "      <td>39.0023</td>\n",
        "      <td>34.9701</td>\n",
        "      <td>34.9096</td>\n",
        "      <td>37.2618</td>\n",
        "      <td>39.6213</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>right_eye_center_x</th>\n",
        "      <td>30.227</td>\n",
        "      <td>29.9493</td>\n",
        "      <td>30.9038</td>\n",
        "      <td>32.0231</td>\n",
        "      <td>32.2448</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>right_eye_center_y</th>\n",
        "      <td>36.4217</td>\n",
        "      <td>33.4487</td>\n",
        "      <td>34.9096</td>\n",
        "      <td>37.2618</td>\n",
        "      <td>38.042</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>left_eye_inner_corner_x</th>\n",
        "      <td>59.5821</td>\n",
        "      <td>58.8562</td>\n",
        "      <td>59.412</td>\n",
        "      <td>60.0033</td>\n",
        "      <td>58.5659</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>left_eye_inner_corner_y</th>\n",
        "      <td>39.6474</td>\n",
        "      <td>35.2743</td>\n",
        "      <td>36.321</td>\n",
        "      <td>39.1272</td>\n",
        "      <td>39.6213</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>left_eye_outer_corner_x</th>\n",
        "      <td>73.1303</td>\n",
        "      <td>70.7227</td>\n",
        "      <td>70.9844</td>\n",
        "      <td>72.3147</td>\n",
        "      <td>72.5159</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>left_eye_outer_corner_y</th>\n",
        "      <td>39.97</td>\n",
        "      <td>36.1872</td>\n",
        "      <td>36.321</td>\n",
        "      <td>38.381</td>\n",
        "      <td>39.8845</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>right_eye_inner_corner_x</th>\n",
        "      <td>36.3566</td>\n",
        "      <td>36.0347</td>\n",
        "      <td>37.6781</td>\n",
        "      <td>37.6186</td>\n",
        "      <td>36.9824</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>right_eye_inner_corner_y</th>\n",
        "      <td>37.3894</td>\n",
        "      <td>34.3615</td>\n",
        "      <td>36.321</td>\n",
        "      <td>38.7541</td>\n",
        "      <td>39.0949</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>right_eye_outer_corner_x</th>\n",
        "      <td>23.4529</td>\n",
        "      <td>24.4725</td>\n",
        "      <td>24.9764</td>\n",
        "      <td>25.3073</td>\n",
        "      <td>22.5061</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>right_eye_outer_corner_y</th>\n",
        "      <td>37.3894</td>\n",
        "      <td>33.1444</td>\n",
        "      <td>36.6032</td>\n",
        "      <td>38.0079</td>\n",
        "      <td>38.3052</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>left_eyebrow_inner_end_x</th>\n",
        "      <td>56.9533</td>\n",
        "      <td>53.9874</td>\n",
        "      <td>55.7425</td>\n",
        "      <td>56.4338</td>\n",
        "      <td>57.2496</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>left_eyebrow_inner_end_y</th>\n",
        "      <td>29.0336</td>\n",
        "      <td>28.2759</td>\n",
        "      <td>27.5709</td>\n",
        "      <td>30.9299</td>\n",
        "      <td>30.6722</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>left_eyebrow_outer_end_x</th>\n",
        "      <td>80.2271</td>\n",
        "      <td>78.6342</td>\n",
        "      <td>78.8874</td>\n",
        "      <td>77.9103</td>\n",
        "      <td>77.7629</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>left_eyebrow_outer_end_y</th>\n",
        "      <td>32.2281</td>\n",
        "      <td>30.4059</td>\n",
        "      <td>32.6516</td>\n",
        "      <td>31.6657</td>\n",
        "      <td>31.7372</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>right_eyebrow_inner_end_x</th>\n",
        "      <td>40.2276</td>\n",
        "      <td>42.7289</td>\n",
        "      <td>42.1939</td>\n",
        "      <td>41.6715</td>\n",
        "      <td>38.0354</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>right_eyebrow_inner_end_y</th>\n",
        "      <td>29.0023</td>\n",
        "      <td>26.146</td>\n",
        "      <td>28.1355</td>\n",
        "      <td>31.05</td>\n",
        "      <td>30.9354</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>right_eyebrow_outer_end_x</th>\n",
        "      <td>16.3564</td>\n",
        "      <td>16.8654</td>\n",
        "      <td>16.7912</td>\n",
        "      <td>20.458</td>\n",
        "      <td>15.9259</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>right_eyebrow_outer_end_y</th>\n",
        "      <td>29.6475</td>\n",
        "      <td>27.0589</td>\n",
        "      <td>32.0871</td>\n",
        "      <td>29.9093</td>\n",
        "      <td>30.6722</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>nose_tip_x</th>\n",
        "      <td>44.4206</td>\n",
        "      <td>48.2063</td>\n",
        "      <td>47.5573</td>\n",
        "      <td>51.8851</td>\n",
        "      <td>43.2995</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>nose_tip_y</th>\n",
        "      <td>57.0668</td>\n",
        "      <td>55.6609</td>\n",
        "      <td>53.5389</td>\n",
        "      <td>54.1665</td>\n",
        "      <td>64.8895</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>mouth_left_corner_x</th>\n",
        "      <td>61.1953</td>\n",
        "      <td>56.4214</td>\n",
        "      <td>60.8229</td>\n",
        "      <td>65.5989</td>\n",
        "      <td>60.6714</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>mouth_left_corner_y</th>\n",
        "      <td>79.9702</td>\n",
        "      <td>76.352</td>\n",
        "      <td>73.0143</td>\n",
        "      <td>72.7037</td>\n",
        "      <td>77.5232</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>mouth_right_corner_x</th>\n",
        "      <td>28.6145</td>\n",
        "      <td>35.1224</td>\n",
        "      <td>33.7263</td>\n",
        "      <td>37.2455</td>\n",
        "      <td>31.1918</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>mouth_right_corner_y</th>\n",
        "      <td>77.389</td>\n",
        "      <td>76.0477</td>\n",
        "      <td>72.732</td>\n",
        "      <td>74.1955</td>\n",
        "      <td>76.9973</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>mouth_center_top_lip_x</th>\n",
        "      <td>43.3126</td>\n",
        "      <td>46.6846</td>\n",
        "      <td>47.2749</td>\n",
        "      <td>50.3032</td>\n",
        "      <td>44.9627</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>mouth_center_top_lip_y</th>\n",
        "      <td>72.9355</td>\n",
        "      <td>70.2666</td>\n",
        "      <td>70.1918</td>\n",
        "      <td>70.0917</td>\n",
        "      <td>73.7074</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>mouth_center_bottom_lip_x</th>\n",
        "      <td>43.1307</td>\n",
        "      <td>45.4679</td>\n",
        "      <td>47.2749</td>\n",
        "      <td>51.5612</td>\n",
        "      <td>44.2271</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>mouth_center_bottom_lip_y</th>\n",
        "      <td>84.4858</td>\n",
        "      <td>85.4802</td>\n",
        "      <td>78.6594</td>\n",
        "      <td>78.2684</td>\n",
        "      <td>86.8712</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>Image</th>\n",
        "      <td>238 236 237 238 240 240 239 241 241 243 240 23...</td>\n",
        "      <td>219 215 204 196 204 211 212 200 180 168 178 19...</td>\n",
        "      <td>144 142 159 180 188 188 184 180 167 132 84 59 ...</td>\n",
        "      <td>193 192 193 194 194 194 193 192 168 111 50 12 ...</td>\n",
        "      <td>147 148 160 196 215 214 216 217 219 220 206 18...</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 69,
       "text": [
        "                                                                           0  \\\n",
        "left_eye_center_x                                                    66.0336   \n",
        "left_eye_center_y                                                    39.0023   \n",
        "right_eye_center_x                                                    30.227   \n",
        "right_eye_center_y                                                   36.4217   \n",
        "left_eye_inner_corner_x                                              59.5821   \n",
        "left_eye_inner_corner_y                                              39.6474   \n",
        "left_eye_outer_corner_x                                              73.1303   \n",
        "left_eye_outer_corner_y                                                39.97   \n",
        "right_eye_inner_corner_x                                             36.3566   \n",
        "right_eye_inner_corner_y                                             37.3894   \n",
        "right_eye_outer_corner_x                                             23.4529   \n",
        "right_eye_outer_corner_y                                             37.3894   \n",
        "left_eyebrow_inner_end_x                                             56.9533   \n",
        "left_eyebrow_inner_end_y                                             29.0336   \n",
        "left_eyebrow_outer_end_x                                             80.2271   \n",
        "left_eyebrow_outer_end_y                                             32.2281   \n",
        "right_eyebrow_inner_end_x                                            40.2276   \n",
        "right_eyebrow_inner_end_y                                            29.0023   \n",
        "right_eyebrow_outer_end_x                                            16.3564   \n",
        "right_eyebrow_outer_end_y                                            29.6475   \n",
        "nose_tip_x                                                           44.4206   \n",
        "nose_tip_y                                                           57.0668   \n",
        "mouth_left_corner_x                                                  61.1953   \n",
        "mouth_left_corner_y                                                  79.9702   \n",
        "mouth_right_corner_x                                                 28.6145   \n",
        "mouth_right_corner_y                                                  77.389   \n",
        "mouth_center_top_lip_x                                               43.3126   \n",
        "mouth_center_top_lip_y                                               72.9355   \n",
        "mouth_center_bottom_lip_x                                            43.1307   \n",
        "mouth_center_bottom_lip_y                                            84.4858   \n",
        "Image                      238 236 237 238 240 240 239 241 241 243 240 23...   \n",
        "\n",
        "                                                                           1  \\\n",
        "left_eye_center_x                                                    64.3329   \n",
        "left_eye_center_y                                                    34.9701   \n",
        "right_eye_center_x                                                   29.9493   \n",
        "right_eye_center_y                                                   33.4487   \n",
        "left_eye_inner_corner_x                                              58.8562   \n",
        "left_eye_inner_corner_y                                              35.2743   \n",
        "left_eye_outer_corner_x                                              70.7227   \n",
        "left_eye_outer_corner_y                                              36.1872   \n",
        "right_eye_inner_corner_x                                             36.0347   \n",
        "right_eye_inner_corner_y                                             34.3615   \n",
        "right_eye_outer_corner_x                                             24.4725   \n",
        "right_eye_outer_corner_y                                             33.1444   \n",
        "left_eyebrow_inner_end_x                                             53.9874   \n",
        "left_eyebrow_inner_end_y                                             28.2759   \n",
        "left_eyebrow_outer_end_x                                             78.6342   \n",
        "left_eyebrow_outer_end_y                                             30.4059   \n",
        "right_eyebrow_inner_end_x                                            42.7289   \n",
        "right_eyebrow_inner_end_y                                             26.146   \n",
        "right_eyebrow_outer_end_x                                            16.8654   \n",
        "right_eyebrow_outer_end_y                                            27.0589   \n",
        "nose_tip_x                                                           48.2063   \n",
        "nose_tip_y                                                           55.6609   \n",
        "mouth_left_corner_x                                                  56.4214   \n",
        "mouth_left_corner_y                                                   76.352   \n",
        "mouth_right_corner_x                                                 35.1224   \n",
        "mouth_right_corner_y                                                 76.0477   \n",
        "mouth_center_top_lip_x                                               46.6846   \n",
        "mouth_center_top_lip_y                                               70.2666   \n",
        "mouth_center_bottom_lip_x                                            45.4679   \n",
        "mouth_center_bottom_lip_y                                            85.4802   \n",
        "Image                      219 215 204 196 204 211 212 200 180 168 178 19...   \n",
        "\n",
        "                                                                           2  \\\n",
        "left_eye_center_x                                                    65.0571   \n",
        "left_eye_center_y                                                    34.9096   \n",
        "right_eye_center_x                                                   30.9038   \n",
        "right_eye_center_y                                                   34.9096   \n",
        "left_eye_inner_corner_x                                               59.412   \n",
        "left_eye_inner_corner_y                                               36.321   \n",
        "left_eye_outer_corner_x                                              70.9844   \n",
        "left_eye_outer_corner_y                                               36.321   \n",
        "right_eye_inner_corner_x                                             37.6781   \n",
        "right_eye_inner_corner_y                                              36.321   \n",
        "right_eye_outer_corner_x                                             24.9764   \n",
        "right_eye_outer_corner_y                                             36.6032   \n",
        "left_eyebrow_inner_end_x                                             55.7425   \n",
        "left_eyebrow_inner_end_y                                             27.5709   \n",
        "left_eyebrow_outer_end_x                                             78.8874   \n",
        "left_eyebrow_outer_end_y                                             32.6516   \n",
        "right_eyebrow_inner_end_x                                            42.1939   \n",
        "right_eyebrow_inner_end_y                                            28.1355   \n",
        "right_eyebrow_outer_end_x                                            16.7912   \n",
        "right_eyebrow_outer_end_y                                            32.0871   \n",
        "nose_tip_x                                                           47.5573   \n",
        "nose_tip_y                                                           53.5389   \n",
        "mouth_left_corner_x                                                  60.8229   \n",
        "mouth_left_corner_y                                                  73.0143   \n",
        "mouth_right_corner_x                                                 33.7263   \n",
        "mouth_right_corner_y                                                  72.732   \n",
        "mouth_center_top_lip_x                                               47.2749   \n",
        "mouth_center_top_lip_y                                               70.1918   \n",
        "mouth_center_bottom_lip_x                                            47.2749   \n",
        "mouth_center_bottom_lip_y                                            78.6594   \n",
        "Image                      144 142 159 180 188 188 184 180 167 132 84 59 ...   \n",
        "\n",
        "                                                                           3  \\\n",
        "left_eye_center_x                                                    65.2257   \n",
        "left_eye_center_y                                                    37.2618   \n",
        "right_eye_center_x                                                   32.0231   \n",
        "right_eye_center_y                                                   37.2618   \n",
        "left_eye_inner_corner_x                                              60.0033   \n",
        "left_eye_inner_corner_y                                              39.1272   \n",
        "left_eye_outer_corner_x                                              72.3147   \n",
        "left_eye_outer_corner_y                                               38.381   \n",
        "right_eye_inner_corner_x                                             37.6186   \n",
        "right_eye_inner_corner_y                                             38.7541   \n",
        "right_eye_outer_corner_x                                             25.3073   \n",
        "right_eye_outer_corner_y                                             38.0079   \n",
        "left_eyebrow_inner_end_x                                             56.4338   \n",
        "left_eyebrow_inner_end_y                                             30.9299   \n",
        "left_eyebrow_outer_end_x                                             77.9103   \n",
        "left_eyebrow_outer_end_y                                             31.6657   \n",
        "right_eyebrow_inner_end_x                                            41.6715   \n",
        "right_eyebrow_inner_end_y                                              31.05   \n",
        "right_eyebrow_outer_end_x                                             20.458   \n",
        "right_eyebrow_outer_end_y                                            29.9093   \n",
        "nose_tip_x                                                           51.8851   \n",
        "nose_tip_y                                                           54.1665   \n",
        "mouth_left_corner_x                                                  65.5989   \n",
        "mouth_left_corner_y                                                  72.7037   \n",
        "mouth_right_corner_x                                                 37.2455   \n",
        "mouth_right_corner_y                                                 74.1955   \n",
        "mouth_center_top_lip_x                                               50.3032   \n",
        "mouth_center_top_lip_y                                               70.0917   \n",
        "mouth_center_bottom_lip_x                                            51.5612   \n",
        "mouth_center_bottom_lip_y                                            78.2684   \n",
        "Image                      193 192 193 194 194 194 193 192 168 111 50 12 ...   \n",
        "\n",
        "                                                                           4  \n",
        "left_eye_center_x                                                    66.7253  \n",
        "left_eye_center_y                                                    39.6213  \n",
        "right_eye_center_x                                                   32.2448  \n",
        "right_eye_center_y                                                    38.042  \n",
        "left_eye_inner_corner_x                                              58.5659  \n",
        "left_eye_inner_corner_y                                              39.6213  \n",
        "left_eye_outer_corner_x                                              72.5159  \n",
        "left_eye_outer_corner_y                                              39.8845  \n",
        "right_eye_inner_corner_x                                             36.9824  \n",
        "right_eye_inner_corner_y                                             39.0949  \n",
        "right_eye_outer_corner_x                                             22.5061  \n",
        "right_eye_outer_corner_y                                             38.3052  \n",
        "left_eyebrow_inner_end_x                                             57.2496  \n",
        "left_eyebrow_inner_end_y                                             30.6722  \n",
        "left_eyebrow_outer_end_x                                             77.7629  \n",
        "left_eyebrow_outer_end_y                                             31.7372  \n",
        "right_eyebrow_inner_end_x                                            38.0354  \n",
        "right_eyebrow_inner_end_y                                            30.9354  \n",
        "right_eyebrow_outer_end_x                                            15.9259  \n",
        "right_eyebrow_outer_end_y                                            30.6722  \n",
        "nose_tip_x                                                           43.2995  \n",
        "nose_tip_y                                                           64.8895  \n",
        "mouth_left_corner_x                                                  60.6714  \n",
        "mouth_left_corner_y                                                  77.5232  \n",
        "mouth_right_corner_x                                                 31.1918  \n",
        "mouth_right_corner_y                                                 76.9973  \n",
        "mouth_center_top_lip_x                                               44.9627  \n",
        "mouth_center_top_lip_y                                               73.7074  \n",
        "mouth_center_bottom_lip_x                                            44.2271  \n",
        "mouth_center_bottom_lip_y                                            86.8712  \n",
        "Image                      147 148 160 196 215 214 216 217 219 220 206 18...  "
       ]
      }
     ],
     "prompt_number": 69
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data.shape[0]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 70,
       "text": [
        "7049"
       ]
      }
     ],
     "prompt_number": 70
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "pix = data.iloc[0,-1]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 71
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "pix = list(map(int, pix.split()))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 72
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import cv2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 73
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "pix = np.array(pix)\n",
      "pix_mat = pix.reshape((96,96))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 74
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "cv2.imwrite('1.jpg',pix_mat)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 75,
       "text": [
        "True"
       ]
      }
     ],
     "prompt_number": 75
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "train_img_path = r'data/train/'\n",
      "nums = data.shape[0]\n",
      "for i in range(nums):\n",
      "    pix = data.iloc[i, -1]\n",
      "    pix_list = list(map(int, pix.split()))\n",
      "    pix_mat = np.array(pix_list).reshape((96, 96))\n",
      "    save_name = os.path.join(train_img_path, str(i)+'.jpg')\n",
      "    cv2.imwrite(save_name, pix_mat)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 34
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import shutil\n",
      "val_img_path = r'data/val/'\n",
      "file_list = os.listdir(train_img_path)\n",
      "val_nums = 50\n",
      "for i in range(val_nums):\n",
      "    ori = os.path.join(train_img_path, file_list[i])\n",
      "    des = os.path.join(val_img_path, file_list[i])\n",
      "    shutil.move(ori, des)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 42
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "train_label = data.drop(['Image'], axis=1)\n",
      "nums = train_label.shape[0]\n",
      "print (nums)\n",
      "train_num = nums-50\n",
      "\n",
      "train_label_split = train_label.iloc[:train_num, :]\n",
      "val_label_split = train_label.iloc[train_num:, :]\n",
      "train_label_split.to_csv('train.csv', header=False, index=False)\n",
      "val_label_split.to_csv('val.csv', header=False, index=False)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "7049\n"
       ]
      }
     ],
     "prompt_number": 80
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "train1 = pd.read_csv('val.csv', header=None)\n",
      "train1.shape[0]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 81,
       "text": [
        "50"
       ]
      }
     ],
     "prompt_number": 81
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import torch\n",
      "import torch.utils.data as data"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 65
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import pandas as pd\n",
      "import numpy as np"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "train_data = pd.read_csv('data/val.csv', header=None)\n",
      "train_data.head().T"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<div style=\"max-width:1500px;overflow:auto;\">\n",
        "<style scoped>\n",
        "    .dataframe tbody tr th:only-of-type {\n",
        "        vertical-align: middle;\n",
        "    }\n",
        "\n",
        "    .dataframe tbody tr th {\n",
        "        vertical-align: top;\n",
        "    }\n",
        "\n",
        "    .dataframe thead th {\n",
        "        text-align: right;\n",
        "    }\n",
        "</style>\n",
        "<table border=\"1\" class=\"dataframe\">\n",
        "  <thead>\n",
        "    <tr style=\"text-align: right;\">\n",
        "      <th></th>\n",
        "      <th>0</th>\n",
        "      <th>1</th>\n",
        "      <th>2</th>\n",
        "      <th>3</th>\n",
        "      <th>4</th>\n",
        "    </tr>\n",
        "  </thead>\n",
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0</th>\n",
        "      <td>64.056093</td>\n",
        "      <td>60.634580</td>\n",
        "      <td>66.864174</td>\n",
        "      <td>64.937280</td>\n",
        "      <td>65.368693</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>1</th>\n",
        "      <td>37.260933</td>\n",
        "      <td>36.189257</td>\n",
        "      <td>38.534931</td>\n",
        "      <td>34.862726</td>\n",
        "      <td>38.011916</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>2</th>\n",
        "      <td>30.224373</td>\n",
        "      <td>34.002416</td>\n",
        "      <td>31.481443</td>\n",
        "      <td>31.687872</td>\n",
        "      <td>31.477397</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>3</th>\n",
        "      <td>41.646520</td>\n",
        "      <td>42.657071</td>\n",
        "      <td>38.059997</td>\n",
        "      <td>36.153965</td>\n",
        "      <td>40.693956</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>4</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>5</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>6</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>7</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>8</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>9</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>10</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>11</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>12</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>13</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>14</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>15</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>16</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>17</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>18</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>19</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>20</th>\n",
        "      <td>41.501613</td>\n",
        "      <td>50.362188</td>\n",
        "      <td>49.054070</td>\n",
        "      <td>47.505600</td>\n",
        "      <td>57.078734</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>21</th>\n",
        "      <td>65.767280</td>\n",
        "      <td>62.440947</td>\n",
        "      <td>64.893855</td>\n",
        "      <td>61.010362</td>\n",
        "      <td>64.344659</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>22</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>23</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>24</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>25</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>26</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>27</th>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "      <td>NaN</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>28</th>\n",
        "      <td>44.007667</td>\n",
        "      <td>51.884082</td>\n",
        "      <td>48.104201</td>\n",
        "      <td>50.088000</td>\n",
        "      <td>56.347272</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>29</th>\n",
        "      <td>81.743373</td>\n",
        "      <td>71.952588</td>\n",
        "      <td>78.429549</td>\n",
        "      <td>74.891194</td>\n",
        "      <td>79.217781</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 22,
       "text": [
        "            0          1          2          3          4\n",
        "0   64.056093  60.634580  66.864174  64.937280  65.368693\n",
        "1   37.260933  36.189257  38.534931  34.862726  38.011916\n",
        "2   30.224373  34.002416  31.481443  31.687872  31.477397\n",
        "3   41.646520  42.657071  38.059997  36.153965  40.693956\n",
        "4         NaN        NaN        NaN        NaN        NaN\n",
        "5         NaN        NaN        NaN        NaN        NaN\n",
        "6         NaN        NaN        NaN        NaN        NaN\n",
        "7         NaN        NaN        NaN        NaN        NaN\n",
        "8         NaN        NaN        NaN        NaN        NaN\n",
        "9         NaN        NaN        NaN        NaN        NaN\n",
        "10        NaN        NaN        NaN        NaN        NaN\n",
        "11        NaN        NaN        NaN        NaN        NaN\n",
        "12        NaN        NaN        NaN        NaN        NaN\n",
        "13        NaN        NaN        NaN        NaN        NaN\n",
        "14        NaN        NaN        NaN        NaN        NaN\n",
        "15        NaN        NaN        NaN        NaN        NaN\n",
        "16        NaN        NaN        NaN        NaN        NaN\n",
        "17        NaN        NaN        NaN        NaN        NaN\n",
        "18        NaN        NaN        NaN        NaN        NaN\n",
        "19        NaN        NaN        NaN        NaN        NaN\n",
        "20  41.501613  50.362188  49.054070  47.505600  57.078734\n",
        "21  65.767280  62.440947  64.893855  61.010362  64.344659\n",
        "22        NaN        NaN        NaN        NaN        NaN\n",
        "23        NaN        NaN        NaN        NaN        NaN\n",
        "24        NaN        NaN        NaN        NaN        NaN\n",
        "25        NaN        NaN        NaN        NaN        NaN\n",
        "26        NaN        NaN        NaN        NaN        NaN\n",
        "27        NaN        NaN        NaN        NaN        NaN\n",
        "28  44.007667  51.884082  48.104201  50.088000  56.347272\n",
        "29  81.743373  71.952588  78.429549  74.891194  79.217781"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "train_data.isnull().sum()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 23,
       "text": [
        "0      0\n",
        "1      0\n",
        "2      0\n",
        "3      0\n",
        "4     50\n",
        "5     50\n",
        "6     50\n",
        "7     50\n",
        "8     50\n",
        "9     50\n",
        "10    50\n",
        "11    50\n",
        "12    50\n",
        "13    50\n",
        "14    50\n",
        "15    50\n",
        "16    50\n",
        "17    50\n",
        "18    50\n",
        "19    50\n",
        "20     0\n",
        "21     0\n",
        "22    50\n",
        "23    50\n",
        "24    50\n",
        "25    50\n",
        "26    50\n",
        "27    50\n",
        "28     0\n",
        "29     0\n",
        "dtype: int64"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "train_data.shape"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 24,
       "text": [
        "(50, 30)"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "train_data.isnull().any().value_counts()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 25,
       "text": [
        "True     22\n",
        "False     8\n",
        "dtype: int64"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "train_data.fillna(method='ffill', inplace=True)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 28
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "train_data.isnull().any().value_counts()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 29,
       "text": [
        "True     22\n",
        "False     8\n",
        "dtype: int64"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "train_data.to_csv('data/train.csv', index=False, header=False)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 17
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}